﻿

CREATE PROCEDURE [dbo].[proc_Employee_CompanyMove_Exec]

AS
	Declare @Count int
	--执行日期<=本月15日
	Set @Count = (select Count(Id) from Employee_CompanyMove where (isexec Is NULL or isexec=0) And execdate <= getdate())
	If(@Count>0)
		Begin
			--更新员工表
			Update Employee  Set Employee.[CompanyId]=Employee_CompanyMove.ACompanyId,
			Employee.DepartmentId=Employee_CompanyMove.ADepartmentId,/*Employee.State=Employee_PostMove.AState*/
			
			Employee.ZhiWu =Employee_CompanyMove.AZhiWu,
			Employee.pid=Employee_CompanyMove.aPid,
			Employee.cid=Employee_CompanyMove.Acid
			 From Employee ,Employee_CompanyMove 
				
				    Where (Employee_CompanyMove.isexec Is NULL or Employee_CompanyMove.isexec=0) 
				          And Employee_CompanyMove.execdate <= getdate()--执行日期<=本月15日
				          And Employee.Id=Employee_CompanyMove.EId
						  And Employee_CompanyMove.Audit=1	
	--更新登录用户表					  
	update aspnet_users set companyid=Employee_CompanyMove.ACompanyId,
	DepartmentId =Employee_CompanyMove.ADepartmentId from Employee_CompanyMove,Employee
	 where aspnet_users.username=Employee.username and Employee_CompanyMove.audit=1 And Employee.Id=Employee_CompanyMove.EId
	 and (Employee_CompanyMove.isexec Is NULL or Employee_CompanyMove.isexec=0) 
				          And Employee_CompanyMove.execdate <= getdate()		  					  
		
			--更新岗位异动表
			Update Employee_CompanyMove Set IsExec=1 
							 Where (Employee_CompanyMove.isexec Is NULL or Employee_CompanyMove.isexec=0) 
				             And Employee_CompanyMove.execdate <=getdate()--执行日期<=本月15日
							 And Employee_CompanyMove.Audit=1
			  
		End
	RETURN

